package com.ch3;

/**
 * @author woldier
 * @version 1.0
 * @description 守护进程
 * @date 2023/4/18 17:19
 **/

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j(topic = "c.Thread")
public class ThreadDemo_11 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {

            while (true) {
                if (Thread.currentThread().isInterrupted()) break;
            }
            log.debug("结束了");
        }, "守护线程");

        thread.setDaemon(true); //设置未守护线程
        log.debug("开启守护线程");
        thread.start();
        TimeUnit.SECONDS.sleep(5);
        log.debug("主线程推出");
    }


}
